var express = require('express');
var router = express.Router();
var path = require('path');

/* GET home page. */
router.get('/works', function(req, res, next) {
  res.sendFile(path.join(__dirname, '../public/works', 'index.html'));
});

/* GET home page. */
router.get('/', function(req, res, next) {
  res.redirect('/works');
});

/* GET home page. */
router.post('/works/views/:key', function(req, res, next) {
  res.render(req.params.key, req.body);
});

// 导入模版
router.get('/works/template/item', function(req, res, next) {
  res.download(path.join(__dirname, '../public/template', '项目导入模版.xlsx'), encodeURIComponent("项目导入模版.xlsx"));
});

// 导入模版
router.get('/works/template/repository', function(req, res, next) {
  res.download(path.join(__dirname, '../public/template', '仓库导入模版.xlsx'), encodeURIComponent("仓库导入模版.xlsx"));
});

// 导入模版
router.get('/works/template/server', function(req, res, next) {
  res.download(path.join(__dirname, '../public/template', '服务器导入模版.xlsx'), encodeURIComponent("服务器导入模版.xlsx"));
});

module.exports = router;
